# Adds two paths (one for cygwin, the other for linux)
# You have to put your cross compiler in /home/user/cross-x86_64 for cygwin
# and in /usr/local/cross-x86_64 for linux
PATH += :/home/user/cross-x86_64/bin:/usr/local/cross-x86_64/bin

SRCS := $(shell find src -name "*.cpp" -o -name "*.S")
OBJS := $(SRCS:.cpp=.o)
OBJS := $(OBJS:.S=.o)

ARCH := x86

ISO := Lymph.iso
KERNEL := Lymph.sys

LIBS := -L. -lgcc -lsupc++
LDFLAGS := -nodefaultlibs -nostdlib -TLinker.ld

INCLUDES := -I./src/Includes \
	-I./src/Includes/Lib \
	-I./src/Includes/Lib/C \
	-I./src/Includes/Hal/SSE
CFLAGS := $(INCLUDES) -Wall -Werror -ffreestanding -nostdinc -nostdlib -mcmodel=kernel -mno-red-zone -march=core2 -O0 -std=c++0x -c

all: $(ISO)

$(ISO): $(KERNEL)
	cp $(KERNEL) iso/boot
	mkisofs -boot-info-table -no-emul-boot -boot-load-size 4 -V "Lymph Live CD" -quiet -b boot/grub/eltorito.img -o $@ iso
	
$(KERNEL): $(OBJS)
	x86_64-elf-ld $(LDFLAGS) $(OBJS) $(LIBS) -o $@

.S.o:
	echo $(OBJS)
	nasm -felf64 $< -o $@
	
.cpp.o:
	x86_64-elf-g++ $(CFLAGS) $< -o $@
	
clean:
	rm -fr $(OBJS) $(ISO) $(KERNEL) iso/boot/$(KERNEL)